function [result] = mat(img)
verbose = false;
original = img;

% Distance Transform with euclidean distance
imgdist = bwdist(img);
if (verbose); figure('name','bwdist'); imshow(imgdist, []); end

% Filtering with a LOG
img = imfilter(imgdist, -fspecial('log',5));
if (verbose); figure('name','log'); imshow(img, []); end

% Average for remove noise
img = img .* imgdist .* imfilter(img,fspecial('average',3));
if (verbose); figure('name','average'); imshow(img, []); end

% Normalization
img = img - min(img(:));
img = img / max(img(:));

img = log(img+0.1);
if (verbose); figure('name','logarithm'); imshow(img, []); end

% Normalization
img = img - min(img(:));
img = img / max(img(:));

img = colfilt(img, [3,3], 'sliding', @satured_sum);
if (verbose); figure('name','satured_sum'); imshow(img, []); end

% Binarization with optimal threshold
img = im2bw(img, graythresh(img));
if (verbose); figure('name','binarization'); imshow(img, []); end

img = bwmorph(img,'spur', Inf);
if (verbose); figure('name','spur'); imshow(img, []); end

% Thin the skeleton for get 1 pixel width
img = bwmorph(img,'thin', Inf);
if (verbose); figure('name','thin'); imshow(img, []); end

% Show comparison between image and generated skeleton
figure('name','result'); imshow(original .* 0.8 + img, []);
result = img;
end

